package com.magpiebridge.controller;

import com.magpiebridge.pojo.Manager;
import com.magpiebridge.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
public class LoginController {

    @Autowired
    private ManagerService managerService;

    @PostMapping("/login")
    public ResponseEntity<String> login(@RequestBody Manager manager) {
        boolean isSuccess = managerService.login(manager);
        if (isSuccess) {
            return ResponseEntity.ok("登录成功，当前登录账号id：" + manager.getId());
        } else {
            return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("账号或密码错误");
        }
    }
}